package com.example.demo.dao;

import com.example.demo.entity.CircleLike;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 点赞相关的表数据库操作类
 */
public interface CircleLikeDao extends JpaRepository<CircleLike,Integer> {
    /**
     * 根据圈子ID和用户ID查找点赞表的数据
     * @param circleId
     * @param userId
     * @return
     */
    List<CircleLike> findByCircleIdAndUserId(int circleId,int userId);

    /**
     * 获取当前登录用户的点赞圈子数量
     * @param userId
     * @return
     */
    @Query(value = "select count(id) from circle_like where user_id = ?1 and status=1",nativeQuery = true)
    int getLikeCount(int userId);

    @Query(value = "select group_concat(nickname) from user where id in  (select user_id from circle_like  where circle_id = ?1 and status=1)",nativeQuery = true)
    String getLikeUsers(int id);
}
